package com.xinnet.mms.cart.service.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xinnet.mms.cart.dao.ShopCartDao;
import com.xinnet.mms.cart.service.ShopCartService;
import com.xinnet.mms.entity.Customer;
import com.xinnet.mms.entity.Goods;
import com.xinnet.mms.entity.ShopCart;
import com.xinnet.mms.enums.ShopCartGoodsTypeEnmu;
import com.xinnet.mms.goods.dao.GoodsDao;
/**
 * 
 * @author 王湛智
 *
 */
@Service("shopCartService")
public class ShopCartServiceImpl implements ShopCartService {

	@Autowired
	private ShopCartDao shopCartDao;
	@Autowired
	private GoodsDao goodsDao;
	
	/**
	 * 根据会员ID取得该会员购物车内的产品
	 */
	@Override
	public List<ShopCart> getShopCartByCusId(String cusId) throws SQLException {
		return shopCartDao.getShopCartByCusId(cusId);
	}

	/**
	 * 查询某个会员的购物车（分页）并将数据封装成Customer对象
	 */
	@Override
	public List<Customer> getShopCartByCusIdPackageToCustomer(String cusId) throws Exception {

		List<ShopCart> shopCartList = shopCartDao.getShopCartByCusId(cusId);

		List<Customer> list=new ArrayList<Customer>();
		Customer customer=new Customer();
		Goods goods=new Goods();
		// 购物车没有商品则处理下一个客户
		if (shopCartList == null || shopCartList.isEmpty()) {
			customer.setProductName("购物车内无商品");
			list.add(customer);
		}
		// 购物车有多条处理方法
		else {
			for (ShopCart cart : shopCartList) {
				Customer cloneCustomer = new Customer();
				goods=goodsDao.getGoodsByGoodsCodes(cart.getGoodsCodes());
				//商品code查不出商品信息处理方法
				if(goods==null || goods.getName()==null || goods.getName().equals("")) {
					if(cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_1.getValue()).toString())){// 1[购买域名]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_1.getLabel());
					}
					else if(cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_2.getValue()).toString())){//2[续费域名]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_2.getLabel());
					}
					else if(cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_3.getValue()).toString())){//3[转入域名]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_3.getLabel());
					}
					else if(cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_4.getValue()).toString())){//4[购买邮局]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_4.getLabel());
					}
					else if(cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_5.getValue()).toString())){//5[购买邮局附属]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_5.getLabel());
					}
					else if(cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_6.getValue()).toString())){//6[续费邮局]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_6.getLabel());
					}
					else if(cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_7.getValue()).toString())){//7[升级邮局]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_7.getLabel());
					}
					else if(cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_8.getValue()).toString())){//8[购买虚机]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_8.getLabel());
					}
					else if(cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_9.getValue()).toString())){//9[购买虚机附属]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_9.getLabel());
					}
					else if(cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_10.getValue()).toString())){//10[续费虚机]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_10.getLabel());
					}
					else if(cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_11.getValue()).toString())){//11[升级虚机]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_11.getLabel());
					}
					else if(cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_12.getValue()).toString())){//12[购买套餐]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_12.getLabel());
					}
					else if(cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_13.getValue()).toString())){//13[VPS购买]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_13.getLabel());
					}
					else if(cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_14.getValue()).toString())){//14[主机租用购买]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_14.getLabel());
					}
					else if (cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_15.getValue()).toString())) {// 15[通用网址购买]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_15.getLabel());
					}
					else if (cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_16.getValue()).toString())) {// 16[通用网址续费]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_16.getLabel());
					}
					else if (cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_17.getValue()).toString())) {// 17[转入通用网址]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_17.getLabel());
					}
					else if (cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_18.getValue()).toString())) {// 18[购买姓名域名]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_18.getLabel());
					}
					else if (cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_19.getValue()).toString())) {// 19[购买一口价域名]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_19.getLabel());
					}
					else if (cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_20.getValue()).toString())) {// 20[域名优先注册]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_20.getLabel());
					}
					else if (cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_21.getValue()).toString())) {// 20[域名优先升级]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_21.getLabel());
					}
					else if (cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_24.getValue()).toString())) {// 24[优先升级特殊渠道]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_24.getLabel());
					}
					else if (cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_22.getValue()).toString())) { // 22[VPS续费]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_22.getLabel());
					}
					else if (cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_23.getValue()).toString())) { // 23[VPS升级]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_23.getLabel());
					}
					else if (cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_25.getValue()).toString())) {// 25[VPS购买附属]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_25.getLabel());
					}
					else if (cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_26.getValue()).toString())) {// 26[购买云邮产品]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_26.getLabel());
					}
					else if (cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_27.getValue()).toString())) {// 27[域名购买附属]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_27.getLabel());
					}
					else if (cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_28.getValue()).toString())) {// 28[特价机购买]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_28.getLabel());
					}
					else if (cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_29.getValue()).toString())) {// 29[购买主机托管]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_29.getLabel());
					}
					else if (cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_30.getValue()).toString())) {// 30[购买主机租用]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_30.getLabel());
					}
					else if (cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_31.getValue()).toString())) {// 31[续费域名附属]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_31.getLabel());
					}
					else if (cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_32.getValue()).toString())) {// 32[me建站购买]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_32.getLabel());
					}
					else if (cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_33.getValue()).toString())) {// 33[me建站续费]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_33.getLabel());
					}
					else if (cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_34.getValue()).toString())) {// 34[云主机服务续费]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_34.getLabel());
					}
					else if (cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_35.getValue()).toString())) {// 35[服务购买]
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_35.getLabel());
					}
					else if (cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_36.getValue()).toString())) {//36老VPS
						cloneCustomer.setProductName(ShopCartGoodsTypeEnmu.ShopCartGoodsType_36.getLabel());
					} 
					else if (cart.getPurchaseCategory().equals((ShopCartGoodsTypeEnmu.ShopCartGoodsType_37.getValue()).toString())) {//37驰云
							cloneCustomer.setProductName("购买驰云");
					}
					else {
						cloneCustomer.setProductName("无法显示该商品信息【"+cart.getPurchaseCategory()+"】]");
					}
				}
				//商品code查询商品不为空处理方法
				else {
					cloneCustomer.setProductName(goods.getName());
				}
				cloneCustomer.setProductLabel(cart.getProductClass());
				cloneCustomer.setAddShopCartTime(cart.getOperateTime());
				
				list.add(cloneCustomer);
			}
		}
		return list;
	}
	
}
